<template>
  <el-dialog
      :title="!form.id ? '新增' : '修改'"
      :close-on-click-modal="false"
      fullscreen
      @close="closeDialog()"
      :visible.sync="visible">
    <el-form :model="form" ref="form" label-width="160px">


      <el-form-item required label="项目编号" prop="projectNumber">
<!--        <el-input v-model="form.projectNumber"></el-input>-->
        <el-select v-model="form.projectNumber" :disabled="form.id != 0" @change="changeProjectCode" placeholder="请选择">
          <el-option
              v-for="item in projectCodeOptions"
              :key="item.prProjectNumber"
              :label="item.prProjectName"
              :value="item.prProjectNumber">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="form.productName"></el-input>
      </el-form-item>

      <el-form-item label="起止日期" prop="startDate">
        <el-date-picker
            v-model="form.startDate"
            type="date"
            format="yyyy日MM月dd日"
            value-format="yyyy日MM月dd日"
            placeholder="选择开始日期">
        </el-date-picker>
        <el-date-picker
            v-model="form.endDate"
            type="date"
            format="yyyy日MM月dd日"
            value-format="yyyy日MM月dd日"
            placeholder="选择结束日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="规格型号" prop="specificationModel">
        <el-input v-model="form.specificationModel"></el-input>
      </el-form-item>

      <el-form-item label="移交日期" prop="handoverDate">
        <el-date-picker
            v-model="form.handoverDate"
            type="date"
            format="yyyy年MM月dd日"
            value-format="yyyy年MM月dd日"
            placeholder="选择移交日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="移交人" prop="handoverPerson">
        <el-input v-model="form.handoverPerson"></el-input>
      </el-form-item>

      <el-form-item label="接收人" prop="receiver">
        <el-input v-model="form.receiver"></el-input>
      </el-form-item>

      <el-form-item label="此表所列资料经准予归档" prop="checkList">
        <el-switch v-model="form.checkList"></el-switch>
      </el-form-item>

      <el-form-item label="资料名称共几页" prop="technicalDocumentsName">
        <el-input v-model="form.technicalDocumentsName"></el-input>
      </el-form-item>

      <el-form-item label="任务流程记录" prop="taskFlowRecordList">
        <el-checkbox-group v-model="form.taskFlowRecordList">
          <el-checkbox label="1">检验结果报告审批流程表；</el-checkbox>
          <el-checkbox label="2">试验鉴定任务通知单；</el-checkbox>
          <el-checkbox label="3">农业机械试验鉴定委托书（适用时）；</el-checkbox>
          <el-checkbox label="4">国家支持的农业机械推广鉴定任务通知书（适用时）；</el-checkbox>
          <el-checkbox label="5">农业机械试验鉴定申请表； </el-checkbox>
          <el-checkbox label="6">试验鉴定申请信息确认记录表；</el-checkbox>
          <el-checkbox label="7">农业机械试验鉴定项目调整单（适用时）；</el-checkbox>
          <el-checkbox label="8">试验鉴定实施中信息变更申请表（适用时）；</el-checkbox>
          <el-checkbox label="9">产品规格表；</el-checkbox>
          <el-checkbox label="10">抽样单/验样单；</el-checkbox>
          <el-checkbox label="11">样品传递卡。</el-checkbox>
        </el-checkbox-group>
      </el-form-item>

      <el-form-item label="补充资料" prop="supplementaryMaterials">
        <el-input v-model="form.supplementaryMaterials"></el-input>
      </el-form-item>

      <el-form-item label="共几页" prop="totalPage">
        <el-input v-model="form.totalPage"></el-input>
      </el-form-item>

      <el-form-item label="检测记录" prop="checkRecordList">
        <el-checkbox-group v-model="form.checkRecordList">
          <el-checkbox label="1">主要仪器设备记录表；</el-checkbox>
          <el-checkbox label="2">一致性检查记录；</el-checkbox>
          <el-checkbox label="3">安全性评价记录；</el-checkbox>
          <el-checkbox label="4">适用性评价记录；</el-checkbox>
          <el-checkbox label="5">可靠性评价记录；</el-checkbox>
          <el-checkbox label="6">用户名单及用户调查表。</el-checkbox>
        </el-checkbox-group>
      </el-form-item>

      <el-form-item label="补充资料" prop="supplementaryMaterials">
        <el-input v-model="form.supplementaryMaterialsCheck"></el-input>
      </el-form-item>

      <el-form-item label="共几页" prop="totalPageCheck">
        <el-input v-model="form.totalPageCheck"></el-input>
      </el-form-item>

      <el-form-item label="其它相关技术资料" prop="otherTechnicalDocumentsTotalList">
        <el-checkbox-group v-model="form.otherTechnicalDocumentsList">
          <el-checkbox label="1">企业法人营业执照(复印件)；</el-checkbox>
          <el-checkbox label="2">产品标准；</el-checkbox>
          <el-checkbox label="3">使用说明书；</el-checkbox>
          <el-checkbox label="4">样机照片（三个方向）；</el-checkbox>
          <el-checkbox label="5">产品商标注册文件（适用时）；</el-checkbox>
          <el-checkbox label="6">可采信的检验检测报告（适用时）；</el-checkbox>
          <el-checkbox label="7">国家环保部门排气污染物检验报告或环保信息社会公开文件（复印件 适用时）。</el-checkbox>
        </el-checkbox-group>
      </el-form-item>

      <el-form-item label="补充资料" prop="supplementaryMaterials">
        <el-input v-model="form.supplementaryMaterialsOtherTechnicalDocuments"></el-input>
      </el-form-item>

      <el-form-item label="共几页" prop="otherTechnicalDocumentsTotalPage">
        <el-input v-model="form.otherTechnicalDocumentsTotalPage"></el-input>
      </el-form-item>

      <el-form-item label="推广鉴定报告及检验报告" prop="promotionIdentificationReportAndInspectionReport">
        <el-checkbox-group v-model="form.promotionIdentificationReportAndInspectionReportList">
          <el-checkbox label="1">推广鉴定报告底稿；</el-checkbox>
          <el-checkbox label="2">推广鉴定报告；</el-checkbox>
          <el-checkbox label="3">检验报告底稿；</el-checkbox>
          <el-checkbox label="4">检验报告。</el-checkbox>
        </el-checkbox-group>
      </el-form-item>

      <el-form-item label="共几页" prop="promotionIdentificationReportAndInspectionReportTotalPage">
        <el-input v-model="form.promotionIdentificationReportAndInspectionReportTotalPage"></el-input>
      </el-form-item>

      <el-form-item label="备注" prop="remarks">
        <el-input type="textarea" v-model="form.remarks"></el-input>
      </el-form-item>

      <el-form-item label="说明">
        <p>
          ⒈移交资料按表中顺序排列装订，在□中填入“√”； 标注“适用时”的选项则按实际情况填入“√”或“×”；<br/>
          ⒉表中未包括但需补充的内容，请在补充资料栏内注明资料名称，序号顺延。<br/>
          ⒊各部分资料页数统计后，在对应栏内填入总页数；<br/>
          ⒋同一企业内容相同的资料在□中选“○”并在备注中注明“见GXXXXTJXXX报告资料”。<br/>
        </p>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog()">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: {
    id: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      visible: false,
      form: {
        id: null,
        projectNumber: '',
        productName: '',
        startDate: '',
        endDate: '',
        specificationModel: '',
        handoverDate: '',
        handoverPerson: '',
        receiver: '',
        checkList: false,
        technicalDocumentsName: '',
        taskFlowRecord: '',
        taskFlowRecordList: [],
        supplementaryMaterials: '',
        totalPage: '',
        checkRecord: '',
        supplementaryMaterialsCheck: '',
        checkRecordList: [],
        totalPageCheck: '',
        otherTechnicalDocuments: '',
        otherTechnicalDocumentsList: [],
        supplementaryMaterialsOtherTechnicalDocuments: '',
        otherTechnicalDocumentsTotalPage: '',
        promotionIdentificationReportAndInspectionReport: '',
        promotionIdentificationReportAndInspectionReportList: [],
        promotionIdentificationReportAndInspectionReportTotalPage: '',
        remarks: '',
      },
      projectCodeOptions: [],
      projectCodeMap: {}
    }
  },
  mounted() {
    this.getProductCode();
  },
  methods: {
    changeProjectCode(val) {
      this.form.productName = this.projectCodeMap[val].prProjectName;
    },
    getProductCode(){
      this.$http({
        url: this.$http.adornUrl('/reportapproval/product/getProjectNumber'),
        method: 'get',
        data: this.$http.adornParams({})
      }).then((data) => {
        if (data && data.code === 0) {
          this.projectCodeOptions = data.productList;
          this.projectCodeOptions.forEach(item => this.projectCodeMap[item.prProjectNumber] = item);
        }else {
          this.$message.error(data.msg)
        }
      })
    },
    init(id) {
      this.form.id = id || 0
      this.visible = true;
      this.resetForm();
      console.log(this.form.id);
      this.$nextTick(() => {
        if (this.form.id) {
          this.$http({
            url: this.$http.adornUrl(`/handoverChecklist/${id}`),
            method: 'get',
          }).then(res => {
            if (res.code === 0) {
              this.form = res.data;
              this.form.taskFlowRecordList = this.form.taskFlowRecord.split(',');
              this.form.checkRecordList = res.data.checkRecord.split(',');
              this.form.otherTechnicalDocumentsList = res.data.otherTechnicalDocuments.split(',');
              this.form.promotionIdentificationReportAndInspectionReportList = res.data.promotionIdentificationReportAndInspectionReport.split(',');
            }
          })
        }
      })
    },
    closeDialog() {
      this.resetForm();
      this.$emit('closeDialog');
    },
    resetForm() {
      // this.$refs.form.resetFields();
      this.form.taskFlowRecordList = [];
      this.form.checkRecordList = [];
      this.form.supplementaryMaterialsOtherTechnicalDocuments = [];
      this.form.promotionIdentificationReportAndInspectionReportList = [];
    },
    // 表单提交
    submit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.form.taskFlowRecord = this.form.taskFlowRecordList.join(',');
          this.form.checkRecord = this.form.checkRecordList.join(',');
          if (this.form.supplementaryMaterialsOtherTechnicalDocuments.length > 0){
            this.form.otherTechnicalDocuments = this.form.otherTechnicalDocumentsList.join(',');
          }else {
            this.form.otherTechnicalDocuments = '';
          }
          this.form.promotionIdentificationReportAndInspectionReport = this.form.promotionIdentificationReportAndInspectionReportList.join(',');
          this.$http({
            url: this.$http.adornUrl(`/handoverChecklist`),
            method: this.form.id ? 'put' : 'post',
            data: this.form
          }).then((data) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('');
                  this.$emit('refreshDataList')
                  this.closeDialog();
                }
              })
            } else {
              this.$message.error(data.msg)
              this.closeDialog();
            }
          })
        }
      })
    }
  }
}
</script>
